package level4.tools.fps
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.utils.getTimer;
	
	import level4.display.GameDispose;
	import level4.interfaces.IGameComponent;

	public class FPS extends GameDispose implements IGameComponent
	{
		private var text:TextField;
		
		private var lastTime:Number = 0;
		private var elaspedTime:Number = 0;
		private var fps:int = 0;
		public function FPS()
		{
			text = new TextField();
			addChild(text);
		}
		override public function init(e:Event):void{
			super.init(e);
		} 
		override public function deInit(e:Event):void{
			super.deInit(e);
			removeAllChildren();
		}
		/**
		 * 更新
		 * */
		public function update(timeDiff:Number):void{
						elaspedTime += timeDiff;
			if(elaspedTime >= 1000){
				elaspedTime = 0;
				text.text = fps.toString();
				fps = 0;
			}else{
				fps ++;
			}
		} 
	}
}